#include "testlib.h"
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
using namespace std;

// 检查路径是否有效
bool isValidPath(const vector<int>& path, int n, const map<int, set<int>>& graph) {
    if (path.size() < 2) return false;
    
    // 检查所有节点是否在范围内
    for (int node : path) {
        if (node < 1 || node > n) return false;
    }
    
    // 检查路径中是否有重复节点
    set<int> uniqueNodes(path.begin(), path.end());
    if (uniqueNodes.size() != path.size()) return false;
    
    // 检查路径中的每条边是否存在
    for (size_t i = 0; i < path.size() - 1; i++) {
        int u = path[i];
        int v = path[i + 1];
        if (graph.find(u) == graph.end() || graph.at(u).find(v) == graph.at(u).end()) {
            return false;
        }
    }
    
    return true;
}

int main(int argc, char* argv[]) {
    registerTestlibCmd(argc, argv);
    
    int t = inf.readInt();
    
    for (int tc = 0; tc < t; tc++) {
        // 读取输入
        int n = inf.readInt();
        int m = inf.readInt();
        int x = inf.readInt();
        int y = inf.readInt();
        
        // 构建图
        map<int, set<int>> graph;
        for (int i = 0; i < m; i++) {
            int u = inf.readInt();
            int v = inf.readInt();
            graph[u].insert(v);
            graph[v].insert(u);
        }
        
        // 读取标准答案
        string ansLine = ans.readLine();
        stringstream ansStream(ansLine);
        vector<int> ansPath;
        int node;
        while (ansStream >> node) {
            ansPath.push_back(node);
        }
        
        // 读取用户答案
        string oufLine;
        try {
            oufLine = ouf.readLine();
        } catch (const exception& e) {
            quitf(_wa, "测试用例 %d: 无法读取用户输出", tc + 1);
        }
        
        stringstream oufStream(oufLine);
        vector<int> userPath;
        while (oufStream >> node) {
            userPath.push_back(node);
        }
        
        // 检查路径是否有效
        if (!isValidPath(userPath, n, graph)) {
            quitf(_wa, "测试用例 %d: 用户输出的路径无效", tc + 1);
        }
        
        // 检查起点和终点
        if (userPath.front() != x || userPath.back() != y) {
            quitf(_wa, "测试用例 %d: 路径的起点或终点不正确", tc + 1);
        }
        
        // 检查是否是字典序最小的路径
        if (userPath != ansPath) {
            quitf(_wa, "测试用例 %d: 路径不是字典序最小的", tc + 1);
        }
    }
    
    // 如果通过检查，则输出正确
    quitf(_ok, "答案正确");
}